package com.dora.http.caseapi;

import com.alibaba.fastjson.JSONObject;
import com.dora.http.base.headerfilter.DefHeadersFilter;
import com.dora.http.base.headerfilter.RequestResLogFilter;
import com.dora.http.requestbuilder.RequestHttpBuilder;
import com.dora.http.utils.JSONSerializer;
import lombok.extern.slf4j.Slf4j;
import org.testng.annotations.Test;

import java.util.HashMap;
import java.util.Map;

/**
 * @Author: Dora
 * @Description: TODO
 * @Date: 2021/12/14
 */
@Slf4j
public class SimpleCaseApiDome {
    RequestHttpBuilder builder = RequestHttpBuilder.create().setBaseUrl("http://172.18.130.52").setProt(45679);
//    RequestHttpBuilder builder = RequestHttpBuilder.create().setBaseUrl("http://192.168.25.11").setProt(4000);
//    RequestHttpBuilder builder = RequestHttpBuilder.create().setBaseUrl("http://172.18.130.52").setProt(45679);
//    RequestHttpBuilder builder = RequestHttpBuilder.create().setBaseUrl("http://172.18.130.52").setProt(45679);
//    RequestHttpBuilder builder = RequestHttpBuilder.create().setBaseUrl("http://172.18.130.52").setProt(45679);
//    RequestHttpBuilder builder = RequestHttpBuilder.create().setBaseUrl("http://172.18.130.52").setProt(45679);
//    RequestHttpBuilder httpBuilder = builder.setBaseUrl("https://172.18.130.52:45689");
//    RequestHttpBuilder httpBuilder = builder.setBaseUrl("http://192.168.25.11:4000");
//    RequestHttpBuilder httpBuilder = builder.setBaseUrl("ws://172.18.130.52:45679");
//    RequestHttpBuilder httpBuilder = builder.setBaseUrl("ws://192.168.25.11:4000");


    @Test
    public void postApi(){
        String path = "/api/v2/grayscale/config";
//        String path = "/api/v2/grayscale/config";
        DefHeadersFilter defHeadersFilter = new DefHeadersFilter();
        Map<String, String> defHeaders = defHeadersFilter.defHeaders();
        defHeaders.put("deviceType","Android 25");
        defHeaders.put("Content-Type", "application/json;charset=utf-8");
        JSONObject object = new JSONObject();
        String requestJson = JSONSerializer.serialize(object);
        RequestHttpBuilder.create().post(defHeaders,requestJson,path,new RequestResLogFilter());
    }
    @Test
    public void getApi(){
        
//        String path = "/api/v2/grayscale/getdefaultconfig";
        String path = "/api/v2/grayscale/getdefaultconfig";
//        String path = "/static/mkipo/index.html";
//        String path = "/web/index.html";
//        String path = "/web/index.html";
//        String path = "ws://172.18.130.52:45679/web/index.html";
        Map<String,String> headers = new HashMap<String,String>();
        HashMap<String,String> params = new HashMap();
        headers.put("Upgrade","websocket");
        headers.put("Connection","Upgrade");
        headers.put("Content-Type", "application/json;charset=utf-8");

        for(int i = 0; i < 1; ++i){
            builder.get(params,path,new RequestResLogFilter());
        }

    }
    @Test
    public void wsApi(){
        String path = "http://172.18.130.52:45679/api/v2/grayscale/getdefaultconfig";

    }


    @Test
    public void optionsApi(){
        String path = "https://172.18.130.52:45689/static/mkipo/index.html";
//        String path = "http://192.168.15.112:4000";
        Map<String,String> setHeaders = new DefHeadersFilter().defHeaders();
        setHeaders.put("Access-Control-Allow-Origin","*");
//        setHeaders.put("Access-Control-Allow-Headers","Origin, X-Requested-With, Content-Type");
//        setHeaders.put("Access-Control-Allow-Methods","POST, GET, PUT, OPTIONS, DELETE");
        for(int i = 0; i < 10; ++i){
            RequestHttpBuilder.create().options(setHeaders,path,new RequestResLogFilter());
        }



    }
}
